window._WOODSHOP = {

    _MAINLABEL:null,

    _BASEGOLD:100000000,

    _ADDGOLD:100000000,

    _BASEPER:1.001,

    _ADDPER:0.001,

    showWoodShop:function(parentNode){

        var uiObj = _GRM.getNodeObj('woodShop');
        var mainLabel = uiObj.node;
        _WOODSHOP._MAINLABEL = mainLabel;

        if(uiObj.isnew){
            _WOODSHOP.initButton(mainLabel);
        }
        _WOODSHOP.refresh();
        parentNode.addChild(mainLabel);
        return mainLabel;

    },


    getPriceStr:function(){

        //return _WOODSHOP.getWoodPrice().toString().replace(/(\.\d{2})\d*$/, "$1");
        return _WOODSHOP.getWoodPrice();
    },

    getWoodPrice:function(){
        var currentShopLevel = _GAMEDATAHELPER.getShopLevel('木头回收商');
        //return _WOODSHOP._BASEPER+_WOODSHOP._ADDPER*currentShopLevel;
        return _WOODSHOP._BASEGOLD+currentShopLevel*_WOODSHOP._ADDGOLD;
    },

    refresh:function(){
        if(_WOODSHOP._MAINLABEL){
            var currentShopLevel = _GAMEDATAHELPER.getShopLevel('木头回收商')+1;
            var woodprice = _WOODSHOP.getWoodPrice();
            _WOODSHOP._MAINLABEL.getChildByName('tips').getChildByName('desc')
            .getComponent(cc.Label).string 
            ="木头回收商等级:"+currentShopLevel+
             "\n回收价格:"+woodprice+
             "\n升级所需:"+window.gameData.wood+"/10"+
             "\n金:"+window.gameData.gold+
             "\n木:"+window.gameData.wood;
        }
    },

    initButton:function(mainLabel){

        var btnUp = mainLabel.getChildByName('tips').getChildByName('btnUp');
        var btnSell = mainLabel.getChildByName('tips').getChildByName('btnSell');
        var mask = mainLabel.getChildByName('mask');

        mask.on(cc.Node.EventType.TOUCH_START, function(){
            _GRM.putNode(this);
        }, mainLabel);

        btnUp.on(cc.Node.EventType.TOUCH_START, function(){
            if(_GAMEDATAHELPER.upShopLevel('木头回收商')){
                _WOODSHOP.refresh();
            }else{
                _TIPS.showMessage('木头不足升级失败');
            }
        }, mainLabel);

        btnSell.on(cc.Node.EventType.TOUCH_START, function(){
            var woodprice = _WOODSHOP.getWoodPrice();
            if(_GAMEDATAHELPER.oprWood(-1)){
                _GAMEDATAHELPER.oprMoney(woodprice);
                //window.gameData.gold = Math.floor(window.gameData.gold*woodprice);
                _WOODSHOP.refresh();
            }else{
                _TIPS.showMessage('木头不足回收失败');
            }
        }, mainLabel);
    }

}